package com;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

//该拦截器定义在包外
public class MyInterceptor implements HandlerInterceptor {

	private Logger  log= LoggerFactory.getLogger(MyInterceptor.class);

	//操作前
	@Override
	public boolean preHandle(HttpServletRequest httpServletRequest,
			HttpServletResponse httpServletResponse, Object handler) throws Exception {
		HandlerMethod handlerMethod =(HandlerMethod)handler;
		log.info("*****MyInterceptor.preHandle*****"+handlerMethod.getBean().getClass().getSimpleName());

		//返回false不继续请求    true继续请求
		return true;
	}
	//操作后
	@Override
	public void postHandle(HttpServletRequest httpServletRequest,
			HttpServletResponse httpServletResponse, Object handler, ModelAndView modelAndView)
			throws Exception {

		HandlerMethod handlerMethod =(HandlerMethod)handler;
		log.info("*****MyInterceptor.postHandle*****"+handlerMethod.getBean().getClass().getSimpleName()+"---"+modelAndView);
	}
	//操作完成
	@Override
	public void afterCompletion(HttpServletRequest httpServletRequest,
			HttpServletResponse httpServletResponse, Object handler, Exception e) throws Exception {
		HandlerMethod handlerMethod =(HandlerMethod)handler;
		log.info("*****MyInterceptor.afterCompletion*****"+handlerMethod.getBean().getClass().getSimpleName());

	}
}
